import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int v=in.nextInt();
        int n=in.nextInt();
        int[] arr=new int[n+1];
        for(int i=1;i<=n;i++){
            arr[i]=in.nextInt();
        }
        int[][] dp=new int[n+1][v+1];
        for(int i=1;i<=n;i++){
            for(int j=0;j<=v;j++){
                dp[i][j]=dp[i-1][j];
                if(j>=arr[i]){
                    dp[i][j]=Math.max(dp[i][j],dp[i-1][j-arr[i]]+arr[i]);
                }
            }
        }
        System.out.println(v-dp[n][v]);
    }
}